<?php

/**
 * This is the model class for table "mission_area".
 *
 * The followings are the available columns in table 'mission_area':
 * @property integer $id
 * @property string $mission_name
 * @property string $mission_description
 * @property integer $mission_number_of_volunteer_needed
 * @property string $mission_location
 * @property string $mission_contact_person_fname
 * @property string $mission_contact_person_lname
 * @property string $mission_contact_mobile
 * @property string $mission_email
 *
 * The followings are the available model relations:
 * @property MissionAssignment[] $missionAssignments
 */
class MissionArea extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return MissionArea the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'mission_area';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('mission_name, mission_description, mission_number_of_volunteer_needed, mission_location, mission_contact_person_fname, mission_contact_person_lname, mission_contact_mobile, mission_email', 'required'),
			array('mission_number_of_volunteer_needed', 'numerical', 'integerOnly'=>true),
			array('mission_name, mission_location, mission_contact_person_fname, mission_contact_person_lname, mission_email', 'length', 'max'=>45),
			array('mission_contact_mobile', 'length', 'max'=>11),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, mission_name, mission_description, mission_number_of_volunteer_needed, mission_location, mission_contact_person_fname, mission_contact_person_lname, mission_contact_mobile, mission_email', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'missionAssignments' => array(self::HAS_MANY, 'MissionAssignment', 'mission_area_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'mission_name' => 'Mission Name',
			'mission_description' => 'Description',
			'mission_number_of_volunteer_needed' => 'Volunteer Needed',
			'mission_location' => 'Location',
			'mission_contact_person_fname' => 'Contact Person Firstname',
			'mission_contact_person_lname' => 'Contact Person Lastname',
			'mission_contact_mobile' => 'Mobile',
			'mission_email' => 'Email',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('mission_name',$this->mission_name,true);
		$criteria->compare('mission_description',$this->mission_description,true);
		$criteria->compare('mission_number_of_volunteer_needed',$this->mission_number_of_volunteer_needed);
		$criteria->compare('mission_location',$this->mission_location,true);
		$criteria->compare('mission_contact_person_fname',$this->mission_contact_person_fname,true);
		$criteria->compare('mission_contact_person_lname',$this->mission_contact_person_lname,true);
		$criteria->compare('mission_contact_mobile',$this->mission_contact_mobile,true);
		$criteria->compare('mission_email',$this->mission_email,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	public function behaviors()
	{
  	  return array(
        'LoggableBehavior'=>
            'application.modules.auditTrail.behaviors.LoggableBehavior',
   	 );
	}
	
	 public function getContactName()
	{
		return $this->mission_contact_person_lname.', '.$this->mission_contact_person_fname;
	}

	public function getMissionName()
	{
		return $this->mission_name;
	}
}